package com.github.livebase.util.template;

import com.github.livebase.util.base.ArraysUtil;

import java.util.Map;

/**
 * @ClassName CompositeStringExpression
 * @description:
 * @author: biao532
 * @create: 2023-12-28 00:28
 * @Version 1.0
 **/
public class CompositeStringExpression implements IExpression {
    private String origin;
    private IExpression[] IExpressions;

    public CompositeStringExpression(String origin, IExpression[] IExpressions) {
        this.origin = origin;
        this.IExpressions = IExpressions;
    }

    public IExpression[] getIExpressions() {
        return IExpressions;
    }

    @Override
    public Object eval(Map<String, ? extends Object> env) {
        StringBuilder builder = new StringBuilder();
        ArraysUtil.foreach(IExpressions, e -> {
            builder.append(e.eval(env));
        });
        return builder.toString();
    }
}
